package algorithm;

public class InsertSortByArray {
   static void insertSort(int[] arr) {
        for (int i = 1; i < arr.length; i++) {
            if (arr[i-1] > arr[i]) {
                int temp = arr[i];
                int j=i-1;
                for (j = i - 1; j >= 0 && temp < arr[j];j--){
                    arr[j+1] = arr[j];
                }
                arr[j+1] = temp;
            }
        }
    }

    public static void main(String[] args) {
        int[] arr = {70,30,40,10,80,20,90,100,75,60,45};
        insertSort(arr);
        for (int i = 0; i <arr.length ; i++) {
            System.out.print(arr[i]+" ");
        }
    }
}
